using System.IO;
using Newtonsoft.Json;
using UnityEngine;

public class MeihuaYiCheckController : MonoBehaviour
{
    public string testStock = "000001"; 
    
    [ContextMenu("GetStockMeihuayiResult")]
    public void GetStockMeihuayiResult()
    {
        StockTranstions st = StocksDataController.instance.GetStockTransitions(testStock);

        var toCheck = st.transitionDatas;//.GetRange(st.transitionDatas.Count - 10, 10);
        int totalCount = toCheck.Count;
        float rightCount = 0;//正确数
        for (int i = 1; i < toCheck.Count; i++)
        {
            var cur = toCheck[i];
            var pre = toCheck[i - 1];
            
            var result = StockMeihuayiCtrl.ZhanWithStockTransition2(st.stockCode,cur, pre);

            rightCount += result.right;
        }

        float rightRate = rightCount / totalCount;
        Debug.Log($"rightCount:{rightCount}, totalCount:{totalCount}, 正确率：{rightRate}");
    }

    [ContextMenu("StockMeihuayiPredictJiResult")]
    public void StocksMeihuayiPredictJiResult()
    {
        StartCoroutine(IEStocksMeihuayiPredictJiResult());
    }
    public System.Collections.IEnumerator IEStocksMeihuayiPredictJiResult()
    {
        float rightRateTotal = 0;
        int totalCount = 0;
        foreach (var stock in StocksDataController.instance.allStocks)
        {
            StockTranstions st = StocksDataController.instance.GetStockTransitions(stock.dm);
            if (st == null)
                continue;

            float result =  StockMeihuayiPredictJiResult(st);
            if (result < 0)
                continue;
            
            rightRateTotal += result;
            totalCount++;

            yield return null;
        }

        float rate = rightRateTotal / totalCount;
        Debug.Log($"总正确率：{rightRateTotal/totalCount}");
    }
    public float  StockMeihuayiPredictJiResult(StockTranstions st)
    {
        if (st == null)  return -1;

        var toCheck = st.transitionDatas;//.GetRange(st.transitionDatas.Count - 10, 10);
        //int totalCount = toCheck.Count;
        float rightCount = 0;//正确数
        float predictJiCount = 0;//预测为吉的个数
        for (int i = 1; i < toCheck.Count; i++)
        {
            var cur = toCheck[i];
            var pre = toCheck[i - 1];
            
            var result = StockMeihuayiCtrl.ZhanWithStockTransition3(st.stockCode,cur, pre);

            rightCount += result.right;
            predictJiCount += result.predictJi;
        }

        if (predictJiCount <= 0) return -1;

        float rightRate = rightCount / predictJiCount;
        Debug.Log($"{st.stockCode} 预测为吉的有{predictJiCount}个，其中涨的有{rightCount}个，正确率为：{rightRate}");
        return rightRate;
    }
    
    [ContextMenu("StockMeihuayiPredictXiongResult")]
    public void StockMeihuayiPredictXiongResult()
    {
        StockTranstions st = StocksDataController.instance.GetStockTransitions(testStock);

        var toCheck = st.transitionDatas;//.GetRange(st.transitionDatas.Count - 10, 10);
        //int totalCount = toCheck.Count;
        float rightCount = 0;//正确数
        float predictXiongCount = 0;//预测为吉的个数
        for (int i = 1; i < toCheck.Count; i++)
        {
            var cur = toCheck[i];
            var pre = toCheck[i - 1];
            
            var result = StockMeihuayiCtrl.ZhanWithStockTransition4(st.stockCode,cur, pre);

            rightCount += result.right;
            predictXiongCount += result.predictXiong;
        }

        float rightRate = rightCount / predictXiongCount;
        Debug.Log($"预测为凶的有{predictXiongCount}个，其中跌的有{rightCount}个，正确率为：{rightRate}");
    }
    
  

}